package com.itjiange.getway.common;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 限流
 * @author ItJianGe
 * @data 2024/4/9 18:10
 */
public class IpKeyResolver implements KeyResolver {

    /**
     * 实现 ip 限流
     * @param exchange
     * @return
     */
    @Override
    public Mono<String> resolve(ServerWebExchange exchange) {
        System.out.println("限流执行了吗？地址：" + exchange.getRequest().getURI().getPath());
        return Mono.just(exchange.getRequest().getRemoteAddress().getAddress().getHostAddress());
    }
}
